package com.eonmind.ai.service.impl;

import com.eonmind.ai.converts.AiChatConvert;
import com.eonmind.ai.dto.AiChatDto;
import com.eonmind.ai.mapper.AiModelCategoryMapper;
import com.eonmind.ai.mapper.AiModelMapper;
import com.eonmind.ai.service.IAiModelCategoryService;
import com.eonmind.common.contract.enums.StatusEnum;
import com.eonmind.common.provider.entity.ai.AiModel;
import com.eonmind.common.provider.entity.ai.AiModelCategory;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

@Slf4j
@Service
public class AiModelCategoryService implements IAiModelCategoryService {
    @Resource
    private AiModelCategoryMapper aiModelCategoryMapper;

    @Resource
    private AiModelMapper aiModelMapper;


    @Override
    public List<AiChatDto.AiModelCategoryData> listModelCategory() {
        List<AiModelCategory> aiModelCategoryList = aiModelCategoryMapper.selectAllByStatus(StatusEnum.OPENED.getCode());
        return AiChatConvert.toAiModelCategoryDataList(aiModelCategoryList);
    }

    @Override
    public List<AiChatDto.AiModelData> listCategoryModels(AiChatDto.AiModelCategoryListRequest request) {
        if (request == null || request.getModelCategoryId() == null) {
            return List.of();
        }
        Long modelCategoryId = request.getModelCategoryId();
        AiModelCategory aiModelCategory = aiModelCategoryMapper.selectById(modelCategoryId);
        if (ObjectUtils.isEmpty(aiModelCategory)) {
            return List.of();
        }
        List<Long> modelIdList = aiModelCategory.getModelIdList();
        List<AiModel> aiModelList = aiModelMapper.selectByIds(modelIdList);
        return AiChatConvert.toAiModelDataList(aiModelList);
    }
}
